import {UserInfoVO} from "@/type/vo/UserInfoVO";
import {diffDYear, tickAsTimeString} from "@/utils/TimeUtil";
import {GenderAsString} from "@/utils/EnumHelper";
import {DictInfoVO} from "@/type/vo/DictInfoVO";

const init = (userInfo: UserInfoVO) => {
    if (userInfo.workingDate) {
        userInfo.workingDateStr = tickAsTimeString(userInfo.workingDate, 'yyyy-MM-dd')
        userInfo.workingTimeStr = tickAsTimeString(userInfo.workingDate, 'yyyy-MM-dd HH:mm:ss')
        const date = new Date(userInfo.workingDate);
        userInfo.workingYear = diffDYear(Date.now(),userInfo.workingDate);
        // console.log('workingTimeStr',userInfo.workingTimeStr)

    }
    if (userInfo.gender) {
        userInfo.genderStr = GenderAsString(userInfo.gender)
    }
}


const initLevel = (userInfo: UserInfoVO, list: Array<DictInfoVO>) => {

    let dictIndex = list.findIndex(x => x.dictId == userInfo.workLevel);
    if (dictIndex >= 0) {
        userInfo.workLevelStr = list[dictIndex].dictName;
    }
}

const initTitle = (userInfo: UserInfoVO, list: Array<DictInfoVO>) => {

    let dictIndex = list.findIndex(x => x.dictId == userInfo.title);
    if (dictIndex >= 0) {
        userInfo.titleStr = list[dictIndex].dictName;
    }
}

const initPosition = (userInfo: UserInfoVO, list: Array<DictInfoVO>) => {

    let dictIndex = list.findIndex(x => x.dictId == userInfo.position);
    if (dictIndex >= 0) {
        userInfo.positionStr = list[dictIndex].dictName;
    }
}

export  default {init, initLevel, initTitle, initPosition}